package com.example.zzl.model.bean.SearchFragment;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.example.zzl.app.MyApplication;
import com.google.gson.Gson;

import java.util.ArrayList;

/**
 * Created by zhang on 2017/2/11.
 */

public class LoadCateData {
    private Data data;

    public LoadCateData(Data data,String url) {
        this.data = data;
        loadData(url);
    }

    private void loadData(String url){
        StringRequest stringRequest = new StringRequest(url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                CateData cateData = new Gson().fromJson(response,CateData.class);
                ArrayList<CateData.ResultBean> resultData = new ArrayList<>();
                for (int i = 0; i < cateData.getResult().size(); i++) {
                    resultData.add(cateData.getResult().get(i));
                }
                data.sendCateData(resultData);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });

        MyApplication.queue.add(stringRequest);

    }
}
